home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1998 February / CD WARE MULTIMEDIA (02-1998) CD++.iso / Encript / HIDE4PGP / HIDE4PGP.DOC < prev    next >
Encoding:
Text File  |  1996-12-19  |  17.2 KB  |  342 lines

  1. Hide4PGP v1.0 - first public version Dec 20, 1996
  2.  
  3. copyrighted software by Heinz Repp, Germany
  4.                         email: 100434.2106@compuserve.com
  5.  
  6. Contents:
  7.  
  8. 1 - Introduction
  9.  
  10. 2 - Commandline Parameters
  11.  
  12. 3 - Technical
  13.  
  14. 4 - Sourcecode
  15.  
  16. 5 - Other Sources
  17.  
  18. 5 - Legal Stuff
  19.  
  20.  
  21.  
  22.  
  23. 1 - Introduction
  24.  
  25. The idea of writing this program came with the public discussion of
  26. limiting or disallowing cryptography for the public, as in France,
  27. upcoming also in the US and Germany.  The tradeoff is to make
  28. encrypted data invisible by hiding them in other files - this is
  29. called steganography.  As encrypted data themselves already resemble
  30. pure (white) noise they should only add some extra noise to other
  31. data.  Henry Hastur was one of the first to add a little program
  32. (Stealth) to the PGP distribution (Pretty Good Privacy by Phil
  33. Zimmermann) to remove (and later add) the PGP header leaving pure
  34. white noise.  I use PGP since years, so I had PGP and Stealth in mind
  35. when planning to write this program.  Stealth acts like a UNIX filter,
  36. so my program should receive or send the encryted data from/to a pipe.
  37. It also works with I/O-redirection ('<' and '>' on the commandline).
  38. Unlike other available steganography programs it has no own
  39. encryption.  I think that PGP itself is unbreakable, additional
  40. encryption doesn't make it any stronger.  In the contrary:  adding an
  41. own cipher adds a header that can be traced.  Just think of extracting
  42. every 1, 2, ...  least significant bits and looking there for known
  43. header structures or coded end of file marks.  PGP files treated with
  44. Stealth have no such weakness.
  45.  
  46. I also had some look at White Noise Storm (tm) by Ray Arachelian and
  47. Steganos v1.4 by Fabian Hansmann.  Steganos came closest to what I
  48. wanted, and the choice of VOC, WAV and BMP files for steganography was
  49. inspired by it.  Both programs do a good job with real quantitative
  50. data, that means true color bitmaps.  Greyscale pictures sometimes
  51. made problems, and 256 colors palette BMP usually showed dramatic
  52. changes.  What is the reason?  Now pixels in 8 bit bitmaps don't hold
  53. a real color but a index to a color table, the palette.  Changing the
  54. least significant bit with real quantitative data makes a difference
  55. of 1 in a range of 255, less than 0.4%, with 2 bits it's 3 out of 255
  56. or 1.2% - still hard to recognize.  With palettes the difference of 1
  57. bit means a different palette entry, and this can be a completely
  58. different color.  Greyscale pictures have also a palette.  Often this
  59. palette contains grey 'colors' in strictly ascending order of
  60. brightness making the palette indices resemble true gray values.  But
  61. sometimes also the palette of a greyscale picture is arbitrarily
  62. mixed.  To make little changes in palette indices correlate to small
  63. color changes, the colors of neighbouring palette positions must be as
  64. similar as possible, or identical.  There are two ways to achieve
  65. this, and they can be combined.  First many bitmaps do not use all
  66. available palette colors or positions.  So one can DUPLICATE as many
  67. entries as possible - preferably the ones most frequently used.  If
  68. those duplicates share the same 7 higher bits, the contents of the
  69. last bit is arbitrary:  the color of the pixel stays the same.  With
  70. quadruplicated entries one can change the last two bits without any
  71. change of the pixel appearance a.s.o.  The second way is to rearrange
  72. the palette entries in a way that similar colors are PAIRED together.
  73. This purpose is not a trivial one, because trying all possibilities is
  74. far beyond capacity.  So some kind of heuristic procedure must do the
  75. job.  Last not least I wanted to be able to use more bits than always
  76. one:  up to 8 with 16 bit data (still less than 0.4%!)  should be
  77. possible.
  78.  
  79. Those were the presuppositions the program should comply with.  And
  80. that is what has come of it:  a program that handles OS/2 1.x, Windows
  81. 3.x or OS/2 2.x uncompressed single image bitmaps with 256 or 16.7 mio
  82. colors, WAV with 8, 12 or 16 bit uncompressed mono or stereo sound
  83. samples and 8 bit VOC files.  I decided to support only bitmaps
  84. because nearly every graphics program can read and write it, and it is
  85. easy to convert the bitmaps after the steganographic process into
  86. another graphics format.  The only prerequisition is the palette must
  87. be preserved and if compression is used it must be without loss, so
  88. JPEG doesn't work, but GIF, TIFF, ...  do.  So with this program most
  89. of the pictures e.g.  used in the WWW / Internet can be used for
  90. steganography.  Use the GIF's of your Homepage ...
  91.  
  92.  
  93. 2 - Commandline Parameters
  94.  
  95. The syntax is simple:  Hide4PGP needs always a file to work on (BMP,
  96. WAV, or VOC) and optionally some switches.  The file needs not to have
  97. the proper extension:  Hide4PGP recognizes the format by the header,
  98. not by the name.  Secret data to be stored into the file is read from
  99. the standard input, but that is usually the keyboard.  So you may want
  100. to specify a pipe ('|' symbol) to use the output of another program,
  101. or redirect a file (with the '<' symbol).  Secret data extracted out
  102. of a file is send to the standard output, that is normally the screen.
  103. Again you may use a pipe or redirect the output to a file ('>'
  104. symbol).  This ideally works with PGP and Stealth in series, e.g.
  105.  
  106. pgp -ef user-ID < file-2-hide | stealth | Hide4PGP datafile
  107.  
  108. encrypts the file <file-2-hide> for the receiver <user-ID>, then
  109. removes the header information leaving pure pseudo random data, and
  110. hides them in the <datafile>.  Alternatively you may specify
  111.  
  112. Hide4PGP datafile < secret.dat
  113.  
  114. to hide secret.dat in datafile.
  115.  
  116. Hide4pgp -x datafile | stealth -a user-ID | pgp -f > decrypted-file
  117.  
  118. extracts the data previously stored in <datafile>, then adds a header
  119. for <user-ID>, decrypts the file and stores the plaintext data in
  120. <decrypted-file>; remember you must set your passphrase before in
  121. PGPPASS when using PGP for decryption in filter mode (or use the -z
  122. switch)!  Alternatively,
  123.  
  124. Hide4PGP -x datafile > secret.dat
  125.  
  126. extracts the data to secrets.dat.
  127.  
  128. Options or switches may be anywhere on the commandline, starting with
  129. '-' or '/'.  Options may be in any order and case, and separate or
  130. combined.  Legal options are:
  131.  
  132. x               eXtract; the default action is hiding.
  133.  
  134. 1,2,4 or 8      means the number of least significant bits to be used;
  135.                 without this parameter the program defaults to 1 bit
  136.                 with 8 bit data and 4 bit with 16 bit data. 8 bit are
  137.                 only allowed with 16 bit data - this should be clear.
  138.                 When extracting you must specify the same parameter as
  139.                 when the file was stored - it is not recorded. (If you
  140.                 forgot or don't know: just try the few possibilities.
  141.  
  142. d[=]            Duplicate palette entries: unused palette entries are
  143.                 replaced with duplicates of those often used. The
  144.                 number of replicates of one entry is always a power of
  145.                 2, this allows the use of the corresponding number of
  146.                 least significant bits without effect on the pixels of
  147.                 this color.
  148.                 If 'd=' is specified then all entries are treated
  149.                 equal if less than 128 colors are used, i.e. all
  150.                 colors appear 2, 4, 8 or ... times. In this case
  151.                 probably not all palette positions will be used. I
  152.                 have no good idea what this can be for, maybe to spare
  153.                 some palette positions for the system palette.
  154.                 The -d option works only with 256 colors bitmaps.
  155.  
  156. p[+]            Pair similar palette entries: Hide4PGP uses two
  157.                 different approaches, one quick single pass and one
  158.                 iterative procedure. The results are in most
  159.                 situations very similar, so the default (p alone) is
  160.                 the quicker first method, 'p+' selects the iterative
  161.                 one. The latter may sometimes need  a not predictable
  162.                 longer period, up to one or two minutes, because it
  163.                 may lead to stable intermediate states where it tries
  164.                 to escape using also random numbers. It will escape,
  165.                 but sometimes (seldom) this takes its time. With a
  166.                 certain bitmap one should try which one gives better
  167.                 results. The -p option works also only with 256 colors
  168.                 bitmaps.
  169.  
  170. v[-]            Verbose: gives detailed information about the data
  171.                 file and the steganographic process. 'v-' suppresses
  172.                 all output except messages of fatal error situations
  173.                 that lead to program abort (UNIX style: say nothing as
  174.                 long everything is o.k.).
  175.  
  176. h or ?          Help; if Hide4PGP finds this option, it shows a help
  177.                 page with short description of all parameters and
  178.                 terminates.
  179.  
  180.  
  181. Hint:  It is advantageous to combine d and p switches.  Many 256 color
  182. bitmaps can be used with the d and p (or p+) switch combined and even
  183. 2 bit / Pixel with little if any change to the picture!
  184.  
  185.  
  186. 3 - Technical
  187.  
  188. Hide4PGP works only on real data in the data file and leaves unused
  189. space untouched.  This allows the data file be converted into other
  190. picture or sound formats that leave the data intact.
  191.  
  192. Usually the secret data don't use the whole data file - after them
  193. random data is inserted to prevent easy detection of modified in
  194. contrast to unmodified data.  There is no end of file mark stored with
  195. the secret data stream, so on extraction always the least significant
  196. bits of the whole file are extracted.  The cryptographic software must
  197. recognize the end of encrypted data by itself - as PGP does with an
  198. encryted end of file sign.  If the secret data cannot be stored
  199. completely a warning is given.  It still can be extracted (the part
  200. that has been stored), but some encryption software like PGP will not
  201. decrypt it at all.  As a rule of thumb using 1 bit requires a datafile
  202. size about 8 times the secret data, 4 times with 2 bit, 2 times with
  203. 4. Double the requirement with 16 bit data.
  204.  
  205. 256 colors bitmaps have often only 100 or less colors.  The
  206. duplication routine sorts the palette entries according to their
  207. frequency, then duplicates them in order, more frequently used first.
  208. If there is place left, the entries are quadruplicated, and so on.
  209. Sometimes it may only be necessary to duplicate all entries, as this
  210. allows using the least significant bit without altering the picture,
  211. or take every entry 16 times because the bitmap has been converted
  212. from a 16 colors format.  The '=' suboption uses an abbreviated code
  213. for this purpose, but there is no disadvantage to leave it off.
  214.  
  215. One word of warning:  using palette entry duplication allows
  216. sophisticated software to detect altered bitmaps because these
  217. palettes have an unusual structure.  But those changes can only be
  218. seen when looking on the palette information - the casual viewer will
  219. not recognize any difference.
  220.  
  221. The two methods for pairing the entries of a 256 color palette need a
  222. measure of similarity.  As distances in the RGB colorspace do not
  223. correlate very good with the human perception I decided to convert the
  224. RGB coordinates into the CIE L*a*b* coordinates as their distances
  225. give a much better correlation.  Conversion formulas for the D65
  226. whitepoint of the ITU 601-1 standard are used.  Most pictures are
  227. viewed with a monitor, and monitors usually have no linear response,
  228. i.e.  the brightness function is more a parabola than a straight line.
  229. That is why I treat the palette RGB coordinates as if they were
  230. precorrected for a gamma value of 2.0 what I feel comes close to the
  231. typical monitor, and the colors we see on the monitor were the real
  232. colors.
  233.  
  234. The pairing methods can be characterized as follows:  The first one
  235. uses an heuristic approach, pairing the palette entries one after
  236. another, giving preference always to that entry with the maximum
  237. distance to its second nearest neighbour, and pairing it with its
  238. nearest.  This gives optimum or nearly optimum pairs in most cases,
  239. but sometimes pairs with exceptional far distances are build.  Those
  240. pairs are repeatedly split by changing partners with another pair that
  241. is 'in the space between' and minimizes the sum of squares of intra
  242. pair distances.  This algorithm was designed somewhat arbitrarily but
  243. proved to produce reliable results.
  244.  
  245. The second method constructs a matrix of reciprocals of the squares of
  246. the distances between every palette entry with every other and 0's in
  247. the main diagonal.  With every iteration cycle every element of the
  248. matrix is replaced by its square divided by row and column sums.  This
  249. tends to leave only one element of every row and column with value 1,
  250. preferably in those representing palette entries with minimal
  251. distance, and all other elements with 0. The palette entries
  252. corresponding to the rows and columns of the 1 elements are then
  253. paired together.  Occasionally this algorithm may produce empty rows
  254. or columns especially with palettes with a large share of identical
  255. entries.  Then the program aborts with a division by zero error.  Care
  256. has been taken to avoid such a situation, but thers's no guaranty.
  257.  
  258. After having grouped all palette entries into pairs, an average color
  259. of every pair is calculated, and then those pairs are again paired
  260. into pairs of pairs representing the next higher bit.  This procedure
  261. is repeated until the palette is completely represented by a binary
  262. tree.  The palette is then rearranged in the order of this binary tree
  263. and all pixels (= indices) changed to reflect the new order.
  264.  
  265. All calculations are done with integer arithmetic and are therefore
  266. pretty fast!  The executable has been compiled using the Microsoft
  267. Quick C 2.5 Compiler in the compact model (code near, data far).
  268.  
  269.  
  270. 4 - Source Code
  271.  
  272. The program is written in ANSI C and should therefore easily be ported
  273. to other systems.  I used standard ANSI calls wherever applicable to
  274. encourage those ports.  There are some exceptions to notice:
  275.  
  276. I had the general assumption that int are 16 bit and long are 32 bit.
  277. If this is not the case with your compiler than a lot of work would
  278. have to be done.
  279.  
  280. The macros GETWORD and PUTWORD are used to read or write 16 bit words
  281. lower byte first.  They are set to 'fputw' and 'fgetw' in in
  282. HIDE4PGP.H.  If your system doesn't have these, you might have to add
  283. your own routines and change the macros.  They must use exactly the
  284. same parameters as fgetc or fputc.
  285.  
  286. The main module HIDE4PGP.C contains a 'setmode' call to set
  287. stdin/stdout to binary and therefore #includes 'io.h'.  As this is not
  288. standard ANSI C, you might have to change it.
  289.  
  290. If your system generally writes or reads 16 or 32 bit values in the
  291. order MSB first, you will have to change all appearances of 'fread'
  292. and 'fwrite' with parameter sizeof (int) or sizeof (long) too.
  293.  
  294. The Makefile provided is a MS Quick C one and of little use for other
  295. compilers.  Generally spoken you need all *.c and the *.h file to
  296. compile to *.o or similar and to be linked to one executable
  297. Hide4PGP.EXE.
  298.  
  299. If you successfully ported this program to another computer system,
  300. please let me hear.  My email address is 100434,2106 at compuserve or
  301. 100434.2106@compuserve.com via Internet.  This is also the address for
  302. bug reports, recommendations or improvements!
  303.  
  304.  
  305. 5 - Other sources
  306.  
  307. Information about the structure of WAV and VOC files I found in an
  308. article by Kai Schwirtzke in c't 1/93, p. 213.  The BMP Windows format
  309. was described in a file named BMP.DOC in one CompuServe graphics forum
  310. - thanks to the unknown author.  Infos about the OS/2 BMP structures I
  311. found in the OS/2 header files of the compiler - and by looking at the
  312. BMP files themselves.  Information about the CIE colorspaces and
  313. conversion formulas I found in the Color spaces FAQ by David Bourgin
  314. (the conversion XYZ -> Lab for L* is wrong!)  and an article by
  315. Michael Haas and Todd Newman of the International Color Consortium,
  316. 'Color Management:  Current Practice and The Adoption of a New
  317. Standard'.  Some of the algorithms are modified from Robert
  318. Sedgewick's 'Algorithms.'
  319.  
  320.  
  321.  
  322. 6 - Legal Stuff
  323.  
  324. You may freely use this software in any environment.  You may make
  325. copies and freely distribute this software provided the archive
  326. contains all files of the original distribution and is not modified in
  327. any way.  You may distribute it in any Freeware / Shareware / PD
  328. collection provided the charge for the data carrier is only nominal
  329. and covers only the media and copying costs.  You may not sell this
  330. program or include it into a for profit product without written
  331. consent of the author.  You may compile the source on any other
  332. computer system.  You may change the source code and distribute the
  333. modified version only if you clearly state all differences, leave the
  334. copyright notice intact and inform the author.
  335.  
  336. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND.
  337. UNDER NO CIRCUMSTANCES SHALL THE AUTHOR BE LIABLE FOR ANY INCIDENTAL,
  338. SPECIAL OR CONSEQUENTIAL DAMAGES (INCLUDING DAMAGES FOR LOSS OF
  339. BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION
  340. AND THE LIKE) ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE
  341. OR ITS DOCUMENTATION.
  342.